package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.Log
import ink.metoo.auto.fishpi.call.ChatRoomCall
import ink.metoo.auto.fishpi.chatroom.Message

class RepeatMessageCommand : Command {

    override val commandText: String = "/复读"

    override fun isMatch(message: Message): Boolean {
        return super.isMatch(message) && message.isMe
    }

    override fun execute(message: Message) {
        try {
            val commandParams = message.commandParams
            val oId = commandParams.getOrNull(1) ?: return
            val messageRaw = ChatRoomCall.getGoodMessageRaw(oId = oId)
            val content = messageRaw?.content
            if (content.isNullOrBlank()) {
                return
            }
            ChatRoomCall.sendMessage(content)
        } catch (e: Exception) {
            Log.debug(e.message, e)
        }

    }

}